module.exports = function ($scope, $state, $stateParams,$resource,$modal,toaster) {
  /* 分页
      * ========================================= */
  $scope.maxSize = 5;             //最多显示多少个按钮
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10         //每页显示几条
  $scope.searchform = {};
  $scope.getCompanyInfo = function () {
    $resource('/api/ac/ggc/reviewCompanyService/getApplyCompanyInfo', {}, {}).save({}, function(res){
        if(res.errcode != 0){ 
            toaster.error({title:"",body:res.errmsg});
            return;
        }
        console.log('查询企业信息是否完整');
        console.log(res);
        if (res.data.msg == '0') {
          if (confirm('请先完善企业信息')) {
            $state.go('app.completeinfo');
          } else {
            $state.go('app.completeinfo');
          }
        }
    });
  }
  $scope.getCompanyInfo();
  $scope.getlist = function () {
      var para = {
          pageNo:$scope.bigCurrentPage, 
          pageSize:$scope.itemsPerPage,
      };
      para = angular.extend($scope.searchform, para);
      $resource('/api/as/ggc/reviewGuide/findDirectoryInfoByUserList', {}, {}).
      save(para,function(res) {
          if (res.errcode !== 0) {
              toaster.error({title:"",body:res.errmsg});
              return;
          }
          $scope.objs = res.data.results;
          $scope.bigTotalItems = res.data.totalRecord;
      })
  };
   
  $scope.getlist(); 
  // 查看
  $scope.toinfo= function (index) {
      $scope.flag = '23';
      $scope.item = $scope.objs[index];			
      var modalInstance = $modal.open({
        template: require('../views/projectGuideInfo.html'),
        controller: 'projectGuideInfo',
        size: 'lg',
        resolve: {
          id: function () {
            return $scope.item.id;
          },
          flag: function () {
              return $scope.flag;
          }
        }
      });
      modalInstance.result.then(function (showResult) {	
          $scope.getlist();
      });
  }

$scope.edit= function (index) {
    $scope.flag = 'edit';
    $scope.item = $scope.objs[index];	
    var modalInstance = $modal.open({
        template: require('../views/projectGuideInfo.html'),
        controller: 'projectGuideInfo',
        size: 'lg',
        resolve: {
          id: function () {
            return $scope.item.id;
          },
          flag: function () {
              return $scope.flag;
          }
        }
      });
      modalInstance.result.then(function (showResult) {	
          $scope.getlist();
      });
}
$scope.issue= function (index) {    
    console.log($scope.objs[index].id) ;          
    if(confirm('是否发布该条指南？')){
        $resource('/api/as/ggc/reviewGuide/updateDirectoryUp', {}, {}).save({'id':$scope.objs[index].id}, function(res){			              
          if(res.errcode === 0 || res.errcode === 10003){
              alert('发布成功')			
              $scope.getlist();
          }else{
              alert(res.errmsg);
          }
      });
    }		
}

  $scope.offline= function (index) {    
      if(confirm('确定下线该指南吗？')){
          $resource('/api/as/ggc/reviewGuide/updateDirectoryDown', {}, {}).save({'id':$scope.objs[index].id}, function(res){			              
              if(res.errcode === 0 || res.errcode === 10003){
                  alert('下线成功')			
                  $scope.getlist();
              }else{
                  alert(res.errmsg);
              }
          });
      }		
  }
  
  
};
